package ToYesterday.Day15_getTreeHigh_S;

import ToYesterday.Day13_TreeNode.TNode;
import org.junit.Test;

public class GetTreeHig {
    TNode T;

    void init(){
        T = new TNode(2);
        TNode n1 = new TNode(3);
        TNode n2 = new TNode(5);
        TNode n3 = new TNode(6);
        TNode n4 = new TNode(12);
        TNode n5 = new TNode(7);
        T.left = n1;
        T.right = n2;
        n1.left = n3;
        n1.right = n4;
        n2 .right = n5;
    }

    @Test
    public void Test(){
        init();
        int sum = sumTreeHigh(T);
        System.out.println(sum);
    }

    public int sumTreeHigh(TNode T){
        if (T==null)return 0;
        if (T.right==null&&T.left==null)return 1;
        int left = sumTreeHigh(T.right);
        int right = sumTreeHigh(T.left);
        int sum = left+right;
        return sum;
    }
}
